package references

import (
	"gvm/instructions/base"
	"gvm/rtda"
	"gvm/rtda/heap"
)

type INVOKE_STATIC struct {
	base.Index16Instruction
}

func (is *INVOKE_STATIC) Execute(jFrame *rtda.JFrame) {
	cp := jFrame.Method().Class().ConstantPool()
	methodRef := cp.GetConstant(is.Index).(*heap.MethodRef)
	method := methodRef.ResolvedMethod()
	if !method.IsStatic() {
		panic("java.lang.IncompatibleClassChangeError")
	}
	class := method.Class()
	if !class.InitStarted() {
		jFrame.RevertNextPC()
		base.InitClass(jFrame.JThread(), class)
		return
	}
	base.InvokeMethod(jFrame, method)
}
